//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.utils.basehelper.collection;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ListUtil {
    public ListUtil() {
    }

    public static <T> List<T> getRandomList(List<T> sources, int num) {
        List<T> oList = new ArrayList();
        if (sources.size() <= num) {
            return sources;
        } else {
            Random random = new Random();

            for(int i = 0; i < num; ++i) {
                int intRandom = random.nextInt(sources.size());
                oList.add(sources.get(intRandom));
                sources.remove(sources.get(intRandom));
            }

            return oList;
        }
    }

    public static <T> List<List<T>> splitList(List<T> list, int len) {
        if (list != null && list.size() != 0 && len >= 1) {
            List<List<T>> result = new ArrayList();
            int size = list.size();
            int count = (size + len - 1) / len;

            for(int i = 0; i < count; ++i) {
                List<T> subList = list.subList(i * len, (i + 1) * len > size ? size : len * (i + 1));
                result.add(subList);
            }

            return result;
        } else {
            return null;
        }
    }
}
